package cn.itcast.util;

import cn.itcast.avro.SseAvro;
import cn.itcast.avro.SzseAvro;
import cn.itcast.bean.CleanBean;

public class QuotUtil {
    //时间过滤,保证数据接受时间在开闭市之间
    //只接受数据时间在开市和闭市之间的数据流
    public static boolean checkTime(Object obj){
        if(obj instanceof SseAvro){
            SseAvro sseAvro = (SseAvro) obj;
            return sseAvro.getTimestamp()<SpecialTimeUtil.closeTime && sseAvro.getTimestamp()>SpecialTimeUtil.openTime;
        }else {
            SzseAvro szseAvro = (SzseAvro) obj;
            return  szseAvro.getTimestamp()<SpecialTimeUtil.closeTime && szseAvro.getTimestamp()>SpecialTimeUtil.openTime;
        }
    }

    //数据过滤
    //过滤数据中最高价、最低价、开盘价和收盘价为0的数据
    public static boolean checkData(Object obj){
        if(obj instanceof SseAvro){
            SseAvro sseAvro = (SseAvro) obj;
            return sseAvro.getHighPrice()!=0 && sseAvro.getLowPrice()!=0 && sseAvro.getOpenPrice()!=0 && sseAvro.getTradePrice()!=0;
        }else {
            SzseAvro szseAvro = (SzseAvro) obj;
            return szseAvro.getHighPrice()!=0 && szseAvro.getLowPrice()!=0 && szseAvro.getOpenPrice()!=0 && szseAvro.getTradePrice()!=0;
        }
    }


    //过滤个股，沪市MD002 ,深市010
    public static boolean isStock(CleanBean cleanBean){
        return cleanBean.getMdStreamId().equals("MD002") || cleanBean.getMdStreamId().equals("010");
    }

    public static boolean isIndex(CleanBean cleanBean) {
        return cleanBean.getMdStreamId().equals("MD001") || cleanBean.getMdStreamId().equals("900");
    }
}
